package pfc.pfcjoc.entities;

// import static playn.core.PlayN.log;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.Fixture;
import org.jbox2d.dynamics.FixtureDef;
import org.jbox2d.dynamics.World;

import pfc.pfcjoc.core.pfcjoc;

import playn.core.GroupLayer;

public class Ramp extends PhysicElement {
  public static String name = "ramp";


  public Ramp(final World world, final GroupLayer worldLayer, final Vec2 pos) {
    super(world, worldLayer, pos);
    setDepth(10);
    initPhysics(world, pos);
  }


  public void initPhysics(World world, Vec2 pos) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.STATIC;
    bodyDef.position = pos;
    body = world.createBody(bodyDef);

    float w = pfcjoc.toPhy(getWidth());
    float h = pfcjoc.toPhy(getHeight());

    Vec2 vertices[] = new Vec2[3];
    vertices[0] = new Vec2(w / 2f, -h / 2f);
    vertices[1] = new Vec2(w / 2f, h / 2f);
    vertices[2] = new Vec2(-w / 2f, h / 2f);

    PolygonShape polygon = new PolygonShape();
    polygon.set(vertices, vertices.length);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.friction = 1.0f;
    fixtureDef.shape = polygon;

    Fixture rampaFxt = body.createFixture(fixtureDef);
    rampaFxt.setUserData("ramp");

    setPosPhy(pos);

    // Útil per gestió de colisions
    body.setUserData(this);
  }


  public void paint(float alpha) {
    super.paint(alpha);
    // sprite.setSprite(spriteIndex);
  }


  public String getName() {
    return name;
  }


  @Override
  public float getWidth() {
    return 32;
  }


  @Override
  public float getHeight() {
    return 32;
  }


  @Override
  protected int getFirstSprite() {
    return 0;
  }


  @Override
  protected String getImagePath() {
    return "images/ramp.png";
  }


  @Override
  protected String getJsonPath() {
    return "images/ramp.json";
  }
}
